package dq.study.designmodel.strategy.sort;

import dq.study.designmodel.strategy.Cat;
import dq.study.designmodel.strategy.Comparable;


/**
 * @author dongqun
 * @Description:
 * @date 2019/4/4 21:16
 */
public class SortUtils {

    public static void sort(Comparable[] source){
        for (int i=source.length;i>0;i--){
            for (int j=0;j<i-1;j++){
                if (source[j].compare(source[j+1])<0){
                    swap(source,j,j+1);
                }
            }
        }
    }

    private static void swap(Comparable[] source,int x,int y){
        Comparable temp = source[x];
        source[x] = source[y];
        source[y] = temp;
    }

    public static void print(Comparable[] source){
        for (int i=0;i<source.length;i++){
            System.out.print(source[i]+" ");
        }
        System.out.println("");
    }
}
